<?php
namespace GracefulTheme\GracefulThemeBundle\Controller;

use Topxia\WebBundle\Controller\BaseController;
use Symfony\Component\HttpFoundation\Request;

class GracefulThemeWebController extends BaseController
{
    public function indexAction(Request $request)
    {
        $themeConfig = $this->getThemeService()->getCurrentThemeConfirmConfig();

        return $this->render('GracefulThemeBundle:Default:show.html.twig', array(
            'themeConfig' => $themeConfig['confirmConfig'],
            'allConfig' => $themeConfig['allConfig'],
            'isIndex' => true
        ));
    }

	public function pendantAction($config=null)
    {
        if (isset($config['code'])) {
            return $this->render("GracefulThemeBundle:Default:{$config['code']}.html.twig",array(
                'config' => $config
            ));
        }
    }

    public function getCurrentConfigColorAction($isIndex=null)
    {
        $config = $this->getThemeService()->getCurrentThemeConfig();
        if ($isIndex) {
            $color = $config['confirmConfig']['color'];
        } else {
            $color = $config['config']['color'];
        }
        return $this->render("GracefulThemeBundle:Default:color.html.twig", array(
            'color' => $color
        )); 
    }

    public function getCurrentConfigBottomAction($isIndex=null)
    {
        $config = $this->getThemeService()->getCurrentThemeConfig();
        if ($isIndex) {
            $config = $config['confirmConfig']['bottom'];
        } else {
            $config = $config['config']['bottom'];
        }

        return $this->render("GracefulThemeBundle:Default:{$config}-bottom.html.twig"); 
    }

    private function getThemeService()
    {
        return $this->getServiceKernel()->createService('Theme.ThemeService');
    }
}